package com.beep.erp.common.widget.refresh.container;

import android.content.Context;
import android.graphics.drawable.AnimationDrawable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.beep.erp.AppContext;
import com.beep.erp.R;
import com.beep.erp.common.glide.GlideImageLoader;


/**
 * FileName: DefaultFooter
 * description:上拉加载动画
 * Author: jolly
 * Date: 2018/8/18
 */
public class DefaultFooter extends BaseFooter {
    private Context context;
    private int rotationSrc;
    private int arrowSrc;
    private int logoSrc;
    private boolean isShowText;

    private AnimationDrawable animationDrawable;

    private TextView footerTitle;
    private ImageView footerArrow;
    private ImageView footerLogo;
    private View frame;

    public DefaultFooter(Context context) {
        this(context, 0, R.mipmap.arrow, 0, false);
    }

    public DefaultFooter(Context context, boolean isShowText) {
        this(context, 0, R.mipmap.arrow, 0, isShowText);
    }

    public DefaultFooter(Context context, int logoSrc) {
        this(context, 0, R.mipmap.arrow, logoSrc, false);
    }

    public DefaultFooter(Context context, int logoSrc, boolean isShowText) {
        this(context, 0, R.mipmap.arrow, logoSrc, isShowText);
    }

    public DefaultFooter(Context context, int rotationSrc, int arrowSrc, int logoSrc, boolean isShowText) {
        this.context = context;
        this.rotationSrc = rotationSrc;
        this.arrowSrc = arrowSrc;
        this.logoSrc = logoSrc;
        this.isShowText = isShowText;
    }

    @Override
    public View getView(LayoutInflater inflater, ViewGroup viewGroup) {
        View view = inflater.inflate(R.layout.refresh_default_footer, viewGroup, true);
        footerTitle = (TextView) view.findViewById(R.id.default_footer_text);
        footerArrow = (ImageView) view.findViewById(R.id.default_footer_arrow);
        footerLogo = (ImageView) view.findViewById(R.id.default_footer_logo);
        frame = view.findViewById(R.id.default_frame);
        if (!isShowText) footerTitle.setVisibility(View.GONE);
        footerArrow.setImageResource(arrowSrc);
        return view;
    }

    @Override
    public int getDragSpringHeight(View rootView) {
        return frame.getMeasuredHeight();
    }

    @Override
    public int getDragLimitHeight(View rootView) {
        return frame.getMeasuredHeight();
    }

    @Override
    public void onPreDrag(View rootView) {
    }

    @Override
    public void onDropAnim(View rootView, int dy) {
    }

    @Override
    public void onLimitDes(View rootView, boolean upORdown) {
        footerTitle.setVisibility(View.GONE);
        if (upORdown) {
            footerTitle.setText(R.string.refresh_footer);

        } else {
            footerTitle.setText(R.string.refresh_footer_up);
        }
    }

    @Override
    public void onStartAnim() {
        footerTitle.setVisibility(View.GONE);
        //    footerArrow.setImageResource(R.drawable.refresh_list_animation);
        GlideImageLoader.load(AppContext.context(), R.mipmap.def, footerArrow);
        //    animationDrawable = (AnimationDrawable) footerArrow.getDrawable();
        //  animationDrawable.start();
    }

    @Override
    public void onFinishAnim() {
        footerTitle.setVisibility(View.GONE);
        footerTitle.setText(R.string.refresh_footer_up);
    }
}
